﻿using System;
using System.Collections.Generic;
using System.Text;
using com.lover.astd.common.logic;
using com.lover.astd.common.model;

namespace com.lover.astd.common.logicexe.equip
{
    public class MhExe : ExeBase
    {
        public MhExe() { _name = ConfigStrings.S_Mh; _readable = ConfigStrings.SR_Mh; }
        public override void init_data() 
        {
            if (_user.Level < 101) return;
            ServiceFactory.getEquipManager().getEquipmentsCanMh(_proto, _logger, _user, "");
            refreshUi();
        }
        public override long execute()
        {
            if (_user.Level < 101) return next_day();
            Dictionary<string, string> conf = getConfig();
            if (conf.ContainsKey(ConfigStrings.enabled) && conf[ConfigStrings.enabled].ToLower().Equals("true"))
            {
                int fail_count_max = 3;
                if (conf.ContainsKey(ConfigStrings.fail_count)) Int32.TryParse(conf[ConfigStrings.fail_count], out fail_count_max);
                int stone_available = getStoneAvailable();
                if (conf.ContainsKey(ConfigStrings.mh_ids))
                {
                    string mh_type = "少量";
                    if (conf.ContainsKey(ConfigStrings.mh_type)) mh_type = conf[ConfigStrings.mh_type];
                    string mh_idstr = conf[ConfigStrings.mh_ids];
                    int result = ServiceFactory.getEquipManager().handleEquipmentsCanMh(_proto, _logger, _user,
                            mh_idstr, fail_count_max, mh_type, stone_available);
                    refreshUi();
                }
            }
            return next_halfhour();
        }
    }
}
